package simple.charlie.rpc.rabbitmq.producer;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@RestController
@AllArgsConstructor
@Slf4j
public class Producer {

	private final RabbitTemplate rabbitTemplate;

	@GetMapping("/messaging/{message}")
	public String message(@PathVariable(value = "message") String message) {
		rabbitTemplate.setReplyTimeout(20000);

		log.info("Send message: {}", message);
		Object response = rabbitTemplate.convertSendAndReceive("rpc.rabbitmq.demo", message);

		log.info("Response: {}", response);
		return "success";
	}
}
